package com.yxzz.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.yxzz.core.domain.PMedicinalRecord;
import com.yxzz.core.service.IPMedicinalRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 中医用药记录Controller
 *
 * @author ruoyi
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/medicinal")
public class PMedicinalRecordController extends BaseController
{
    @Autowired
    private IPMedicinalRecordService pMedicinalRecordService;

    /**
     * 查询中医用药记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PMedicinalRecord pMedicinalRecord)
    {
        startPage();
        List<PMedicinalRecord> list = pMedicinalRecordService.selectPMedicinalRecordList(pMedicinalRecord);
        return getDataTable(list);
    }

    /**
     * 导出中医用药记录列表
     */
    @Log(title = "中医用药记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PMedicinalRecord pMedicinalRecord)
    {
        List<PMedicinalRecord> list = pMedicinalRecordService.selectPMedicinalRecordList(pMedicinalRecord);
        ExcelUtil<PMedicinalRecord> util = new ExcelUtil<PMedicinalRecord>(PMedicinalRecord.class);
        util.exportExcel(response, list, "中医用药记录数据");
    }

    /**
     * 获取中医用药记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pMedicinalRecordService.selectPMedicinalRecordById(id));
    }

    /**
     * 新增中医用药记录
     */
    @Log(title = "中医用药记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PMedicinalRecord pMedicinalRecord)
    {
        return toAjax(pMedicinalRecordService.insertPMedicinalRecord(pMedicinalRecord));
    }

    /**
     * 修改中医用药记录
     */
    @Log(title = "中医用药记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PMedicinalRecord pMedicinalRecord)
    {
        return toAjax(pMedicinalRecordService.updatePMedicinalRecord(pMedicinalRecord));
    }

    /**
     * 删除中医用药记录
     */
    @Log(title = "中医用药记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pMedicinalRecordService.deletePMedicinalRecordByIds(ids));
    }
}
